package com.andy.service.impl;

import com.andy.dao.entity.TUser;
import com.andy.dao.mapper.UserMapper;
import com.andy.service.LoginService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public void login(String username, String password) throws Exception {

        //校验入参
        if(StringUtils.isBlank(username) || StringUtils.isBlank(password)){
            throw new RuntimeException("账户密码不能为空");
        }

        //查询
        TUser userCnd = new TUser();
        userCnd.setUserName(username);
        TUser user = userMapper.getUser(userCnd);

        if(user==null) throw new RuntimeException("账户不存在");

        if(password.equals(user.getPassword())){
            System.out.println("密码验证通过");
        }else{
            throw new RuntimeException("密码错误");
        }
    }
}
